package com.btcode.netty.server.session.util;

import io.netty.channel.Channel;

import java.net.InetSocketAddress;

public final class ChannelUtil {

    public static String getChannelId(Channel channel) {
        if (channel == null) {
            return null;
        }
        return channel.id().asLongText();
    }

    public static String getIp(Channel channel) {
        try {
            return ((InetSocketAddress) channel.remoteAddress()).getAddress().toString().substring(1);
        }
        catch (Exception e) {
            //
        }
        return "";
    }

}  